<template>
  <div>
    <h1>添加管理员</h1>
    <el-form :model="form" label-width="120px">
      <el-form-item label="管理员姓名">
        <el-input v-model="form.adminname" />
      </el-form-item>
      <el-form-item label="角色">
        <el-radio-group v-model="form.role">
          <el-radio :label="1">超级管理员</el-radio>
          <el-radio :label="2">普通管理员</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">添加</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup lang="ts">
import { reactive } from "vue";
import service from "../../../utils/service";
import { ElMessage } from "element-plus";

import { useRouter } from "vue-router";

const $router = useRouter();

interface IAdmin {
  adminname: string;
  role: number;
  password: string,
  checkedKeys: string[]


}

const form = reactive<IAdmin>({
  adminname: "",
  role: 2,
  password:"",
  checkedKeys:[]
});

const onSubmit = () => {
  service({
    url: "/admin/add",
    method: "post",
    data: form
  }).then((res) => {
    if (res.data.code == "200") {
      ElMessage({
        message: "添加成功！",
        type: "success",
      });
      $router.push("/Admin/list2");
    }
  });
};
onSubmit()
</script>

<style>
</style>